package com.xm.conf;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FanoutRabbitConfig {
    public static final String A = "fanout.A";
    public static final String B = "fanout.B";
    public static final String C = "fanout.C";

    @Bean
    public Queue queueFA(){
        return new Queue(A);
    }

    @Bean
    public Queue queueFB(){
        return new Queue(B);
    }

    @Bean
    public Queue queueFC(){
        return new Queue(C);
    }

    @Bean
    FanoutExchange fanoutExchange(){
        return new FanoutExchange("fanoutExchange");
    }

    /**
     * 将队列A和扇形交换机绑定
     */
    @Bean
    Binding bindingFanoutA(){
        return BindingBuilder.bind(queueFA()).to(fanoutExchange());
    }

    /**
     * 将队列B和扇形交换机绑定
     */
    @Bean
    Binding bindingFanoutB(){
        return BindingBuilder.bind(queueFB()).to(fanoutExchange());
    }

    /**
     * 将队列C和扇形交换机绑定
     */
    @Bean
    Binding bindingFanoutC(){
        return BindingBuilder.bind(queueFC()).to(fanoutExchange());
    }
}
